package com.custom.lessonstudy.ui.presenter;

import com.custom.lessonstudy.di.ApiService;
import com.custom.lessonstudy.di.BasePresenter;
import com.custom.lessonstudy.di.SuManHttpService;
import com.custom.lessonstudy.net.BaseHttpResponse;
import com.custom.lessonstudy.net.HttpResponseObserver;
import com.custom.lessonstudy.net.RxSchedulers;
import com.custom.lessonstudy.ui.bean.SmsBean;
import com.custom.lessonstudy.ui.view.MainView;

import java.util.HashMap;

public class MainPresenter extends BasePresenter<MainView> {
    private SuManHttpService suManHttpService;
    private ApiService apiService;

    public MainPresenter() {

        suManHttpService= new SuManHttpService();
//        if (getView() != null) {
//            getView().setData(dataFromNet);
//        }
    }

    public void getData(String type) {
        HashMap map = new HashMap();
        map.put("mobile","15618273672");
        map.put("area_code","+86");
        suManHttpService.sendMsg(map).compose(RxSchedulers.compose()).subscribe(new HttpResponseObserver<BaseHttpResponse<SmsBean>>(){

            @Override
            public void success(BaseHttpResponse<SmsBean> smsBeanBaseHttpResponse) {
                try {

                    if (smsBeanBaseHttpResponse!=null){
                        if (getView() != null) {
                            String msg = smsBeanBaseHttpResponse.msg;
                            getView().onSmsSuccess(type ,msg);
                        }

                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void error(int code, String message) {
                try {
                    if (  getView()!=null){
                        getView().onError(message);
                    }

                } catch (Exception e) {
                    e.printStackTrace();
                }

            }
        });
    }
}